<template>
    <div class="login">
        <div class="loginBox">
            <section></section>
            <el-form ref="loginFrom" :model="loginF" :rules="loginRules">
                <el-form-item prop="username">
                    <el-input prefix-icon="el-icon-search" v-model="loginF.username">
                    </el-input>
                </el-form-item>
                <el-form-item prop="password">
                    <el-input prefix-icon="el-icon-search" v-model="loginF.password">
                    </el-input>
                </el-form-item>



                <el-form-item class="loginFoot">
                    <el-button type="primary" @click="loginAdd">立即创建</el-button>
                    <el-button>取消</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
import { loginRequest } from '@/utils/Login'
import { mapMutations } from 'vuex';
export default {
    data() {
        return {
            loginF: {
                username: '',
                password: ''
            },
            loginRules: {
                username: [
                    { required: true, message: '请输入活动名称', trigger: 'blur' },
                    { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
                ],
                password: [
                    { required: true, message: '请输入活动名称', trigger: 'blur' },
                    { min: 3, max: 6, message: '长度在 3 到 6 个字符', trigger: 'blur' }
                ]
            }

        }
    },
    methods: {
        ...mapMutations(['addToken']),
        loginAdd() {
            this.$refs.loginFrom.validate(async (valid) => {
                if (valid) {
                    let {data:res} = await loginRequest(this.loginF)
                    if(res.meta.status==200){
                        this.$message.success(res.meta.msg)
                        this.addToken(res.data)
                        this.$router.push('/welcome')
                    }else{
                        this.$message.error(res.meta.msg)
                    }
                }
            });
        }
    }
}
</script>

<style lang="scss">
.login {
    width: 100%;
    height: 100%;
    background: #2b4b6b;
    display: flex;
    justify-content: center;
    align-items: center;



    .loginBox {
        width: 400px;
        height: 300px;
        background: white;


        section {
            width: 120px;
            height: 120px;
            background: pink;
            border-radius: 50%;
            position: relative;
            left: 50%;
            transform: translate(-50%, -50%);

        }

        .el-form {
            width: 90%;
            margin: auto;

            .loginFoot {
                display: flex;
                justify-content: flex-end;
            }

        }
    }
}
</style>